# -*- coding: utf-8 -*-
import MySQLdb


class MySQL_db(object):
    def __init__(self):
        self.db = MySQLdb.connect(charset="utf8", host="192.168.7.35", user="root", passwd="12345", db="disease_prediction")
        self.cursor = self.db.cursor()

    def select_info(self, doctor_list):
        sql = """SELECT a.DocName,a.Department,a.Professional_Title,a.Skilled,b.HcoName,b.HcoAdministrativeLevel,
b.HcoLevel from disease_prediction.doctor a LEFT JOIN disease_prediction.hospital b
on a.HcoId=b.HcoId WHERE a.DocId=%d;"""
        list_dir = []
        doctor_name = set()
        param_list = ["DocName", "Department", "Professional_Title", "Skilled", "HcoName", "HcoAdministrativeLevel", "HcoLevel"]
        for td in doctor_list:
            self.cursor.execute(sql % int(td))
            result = self.cursor.fetchone()
            self.db.commit()
            if not result:
                continue
            if result[0] in doctor_name:
                continue
            doctor_name.add(result[0])
            list_dir.append(dict(zip(param_list, list(result))))
        return list_dir


